import request from '@/utils/request'
import { getToken } from "@/utils/auth";

// 查询文档列表
export function listDocument(query) {
  return request({
    url: '/system/document/list',
    method: 'get',
    params: query
  })
}

// 查询文档详细
export function getDocument(documentId) {
  return request({
    url: '/system/document/' + documentId,
    method: 'get'
  })
}

// 新增文档
export function addDocument(data) {
  return request({
    url: '/system/document',
    method: 'post',
    data: data,
  })
}

// 修改文档
export function updateDocument(data) {
  return request({
    url: '/system/document',
    method: 'put',
    data: data,
  })
}

// 删除文档
export function delDocument(documentId) {
  return request({
    url: '/system/document/' + documentId,
    method: 'delete'
  })
}

// 导出文档
export function exportDocument(query) {
  return request({
    url: '/system/document/export',
    method: 'get',
    params: query
  })
}

// 下载文档
export function downloadDocument(documentId) {
  return request({
    url: '/system/document/download/' + documentId,
    method: 'get',
    responseType: 'arraybuffer',
    headers: {
      'Authorization': 'Bearer ' + getToken()
    }
  })
}

// 文档上传接口
export function uploadDocument(data) {
  return request({
    url: '/system/document/upload',
    method: 'post',
    data: data
  })
}

// 获取文档分类树
export function getDocumentCategoryTree() {
  return request({
    url: '/system/document/category/tree',
    method: 'get'
  })
}

export function listCategory(query) {
  return request({
    url: '/system/document/category/list',
    method: 'get',
    params: query
  })
}

// 查询文档分类树结构
export function treeCategory() {
  return request({
    url: '/system/document/category/tree',
    method: 'get'
  })
}

// 查询文档分类详细
export function getCategory(categoryId) {
  return request({
    url: '/system/document/category/' + categoryId,
    method: 'get'
  })
}

// 新增文档分类
export function addCategory(data) {
  return request({
    url: '/system/document/category',
    method: 'post',
    data: data
  })
}

// 修改文档分类
export function updateCategory(data) {
  return request({
    url: '/system/document/category',
    method: 'put',
    data: data
  })
}

// 删除文档分类
export function delCategory(categoryId) {
  return request({
    url: '/system/document/category/' + categoryId,
    method: 'delete'
  })

}
